using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PhysicsController : MonoBehaviour
{
    // self component
    Rigidbody _rigidbody;

    // open param
    [SerializeField] float walkSpeed;

    // cache param
    private float horizontalInputRaw;
    private float verticalInputRaw;

    void Awake()
    {
        _rigidbody = this.GetComponent<Rigidbody>();    
    }
    void Update()
    {
        CalcInputVal();
        MoveByPhysics(Time.deltaTime);
    }
    private void CalcInputVal()
    {
        horizontalInputRaw = Input.GetAxisRaw("Horizontal");
        verticalInputRaw = Input.GetAxisRaw("Vertical");
    }
    private void MoveByPhysics(float deltaTime)
    {
        Vector3 dir = new Vector3(verticalInputRaw, 0, horizontalInputRaw);
        // _rigidbody.velocity = walkSpeed * dir;
        _rigidbody.MovePosition(dir * walkSpeed * deltaTime + transform.position);
    }
}
